<template>
  <div>
    <web-view :src="link" @message="authSubMessage" />
  </div>
</template>

<script>
import { GET_SUB_INFO, emitter } from '@/utils/emitter'
export default {
  data() {
    return {
      show: false,
      link: '',
      info: {
        linkPath: '',
        infoId: '',
      },
    }
  },
  onLoad({ link }) {
    this.link = decodeURIComponent(link)
  },
  onShareAppMessage(opt) {
    return {
      path: `/pages/webview/index?link=${encodeURIComponent(opt.webViewUrl)}`,
    }
  },
  onShareTimeline(opt) {},
  methods: {
    authSubMessage(e) {
      if (e.detail.data[0]) {
        this.info.infoId = e.detail.data[0].split(' ')[1]
        const pairs = this.link.split('&')
        for (let i = 0; i < pairs.length; i++) {
          const pair = pairs[i].split('=')
          if (pair[0] == 'page') {
            this.info.linkPath = decodeURIComponent(pair[1])
          }
        }
      }
      emitter.emit(GET_SUB_INFO, this.info)
    },
  },
}
</script>

<style lang="scss" scoped>

</style>
